import { Get, Post } from '@/api/http.js';
import getRecordsData from '@/mock/getRecords.json';
import getAdminRecordsJSON from '@/mock/getAdminRecords.json';

const { VITE_NODE_ENV } = import.meta.env;
const isLocal = VITE_NODE_ENV === 'local';

// 上传文档
export const processToFile = (data) =>
  Post('/parser/processToFile', data, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });

// 获取生成记录列表
export const getRecords = (data) => (isLocal ? getRecordsData : Get('/parser/getRecords', data));

// 文件下载
export const downloadProcessFile = (data) =>
  Get('/parser/downloadProcessFile', data, {
    responseType: 'blob',
  });

// 生成记录删除
export const deleteRecordById = (data) => Get('/parser/deleteRecordById', data);

// 管理员生产记录
export const getAdminRecords = (data) =>
  isLocal ? Promise.resolve(getAdminRecordsJSON) : Get('/parser/getAdminRecords', data);

// 设置备注
export const appendRecordMoment = (data) => Post('/parser/appendRecordMoment', data, {
  headers: {
    'Content-Type': 'multipart/form-data',
  },
});
